package com.breeze.components.socket.vo;

import com.breeze.components.redis.cluster.id.SnowIdUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * websocket应答
 *
 * @author breeze
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WebSocketResponse<T> {

  private static final String OK_MSG = "ok";
  private static final Integer OK_CODE = 0;

  private String seq;
  private String cmd;
  private WebSocketResult<T> response;

  public static <T> WebSocketResponse<T> ok(String cmd, T data) {
    return ok(cmd, OK_MSG, data);
  }

  public static <T> WebSocketResponse<T> ok(String cmd, String msg, T data) {
    return new WebSocketResponse<>(
        SnowIdUtil.getCommonSnowId().nextIdStr(), cmd, new WebSocketResult<>(OK_CODE, msg, data));
  }

  public static <T> WebSocketResponse<T> ok(String cmd, String msg) {
    return ok(cmd, msg, null);
  }
}
